#%%
import matplotlib.pyplot as plt
import numpy as np
import pickle

pklfiles = [
    # '/mnt/liying.cibr.ac.cn_Data_Temp/multiview_9/chenxf/00_BehaviorAnalysis-seq2seq/SexAge/Day55_Mix_analysis/SexAgeDay55andzzcWTinAUT_MMFF/result32/representitive_k34_filt_perc66/Representive_K34.clippredpkl',
    '/DATA/taoxianming/rat/data/Mix_analysis/SexAgeDay55andzzcWTinAUT_MMFF/result32/semiseq2seq_iter0/output/seq2seq-decSeq/olc-2024-05-23-seq2seq-_pca26.clippredpkl',
    '/DATA/taoxianming/rat/data/Mix_analysis/SexAgeDay55andzzcWTinAUT_MMFF/result32/semiseq2seq_iter0/output/semisupervise-decSeq-iter0-epoch3/olc-2024-05-23-semiseq2seq-iter0-epoch3_pca12.clippredpkl',
    '/DATA/taoxianming/rat/data/Mix_analysis/SexAgeDay55andzzcWTinAUT_MMFF/result32/semiseq2seq_iter0/output/semisupervise-decSeq-iter1-epoch3/olc-2024-05-23-semiseq2seq-iter1-epoch3_pca12.clippredpkl',
    '/DATA/taoxianming/rat/data/Mix_analysis/SexAgeDay55andzzcWTinAUT_MMFF/result32/semiseq2seq_iter0/output/semisupervise-decSeq-iter2-epoch5/olc-2024-05-23-semiseq2seq-iter2-epoch5_pca12.clippredpkl',
    '/DATA/taoxianming/rat/data/Mix_analysis/SexAgeDay55andzzcWTinAUT_MMFF/result32/semiseq2seq_iter0/output/semisupervise-decSeq-iter3-epoch6/olc-2024-05-23-semiseq2seq-iter3-epoch6_pca12.clippredpkl'
]

pklfiles = [
    # '/mnt/liying.cibr.ac.cn_Data_Temp/multiview_9/chenxf/00_BehaviorAnalysis-seq2seq/SexAge/Day55_Mix_analysis/SexAgeDay55andzzcWTinAUT_MMFF/result32/representitive_k34_filt_perc66/Representive_K34.clippredpkl',
    '/DATA/taoxianming/rat/data/Mix_analysis/SexAgeDay55andzzcWTinAUT_MMFF/result32/semiseq2seq_iter0/output/seq2seq-decSeq/olc-2024-05-23-seq2seq-_pca26.clippredpkl',
    '/DATA/taoxianming/rat/data/Mix_analysis/SexAgeDay55andzzcWTinAUT_MMFF/result32/semiseq2seq_iter0.bak/output/semisupervise-decSeq-iter0-epoch3/olc-2024-05-23-semiseq2seq-iter0-epoch3_pca10.clippredpkl',
    '/DATA/taoxianming/rat/data/Mix_analysis/SexAgeDay55andzzcWTinAUT_MMFF/result32/semiseq2seq_iter0.bak/output/semisupervise-decSeq-iter1-epoch3/olc-2024-05-23-semiseq2seq-iter1-epoch3_pca9.clippredpkl',
    '/DATA/taoxianming/rat/data/Mix_analysis/SexAgeDay55andzzcWTinAUT_MMFF/result32/semiseq2seq_iter0.bak/output/semisupervise-decSeq-iter2-epoch3/olc-2024-05-23-semiseq2seq-iter2-epoch3_pca8.clippredpkl',
    '/DATA/taoxianming/rat/data/Mix_analysis/SexAgeDay55andzzcWTinAUT_MMFF/result32/semiseq2seq_iter0.bak/output/semisupervise-decSeq-iter3-epoch3/olc-2024-05-23-semiseq2seq-iter3-epoch3_pca8.clippredpkl',
]

chi_l = []
dbi_l = []
shi_l = []

for pklfile in pklfiles:
    pkldata = pickle.load(open(pklfile, 'rb'))
    cluster_metric = pkldata['cluster_metric']
    chi_l.append(cluster_metric['calinski_harabasz_score'])
    dbi_l.append(cluster_metric['davies_bouldin_score'])
    shi_l.append(cluster_metric['silhouette_score'])


plt.figure(figsize=(6, 4))
plt.subplot(1, 2, 1)
plt.plot(chi_l)
plt.plot([0.5, 0.5], [min(chi_l), max(chi_l)], 'k--')
plt.xlabel('iteration')

plt.title('Calinski-Harabasz Index \n <higher better>')
plt.subplot(1, 2, 2)
plt.plot(dbi_l)
plt.title('Davies-Bouldin Index \n <lower better>')
plt.plot([0.5, 0.5], [min(dbi_l), max(dbi_l)], 'k--')
plt.xlabel('iteration')
